mpi4py - collective communication

by: s3ni, 7 years ago


Hello everybody!

I'm trying to solve the following problem:

I have four processes (rank 0 - 3).
rank 0 should coordinate/stop the other 3 ranks.
rank 1 - 3 are generating random strings, if the string matches with the given one (hardcoded), the process which has the match should send an stop flag to rank 0.

if data == given:
    end = "endflag"
    comm.send(end, dest=0)

If rank 0 receives the stop flag from MIP.ANY_SOURCE i want him to send an broadcast or something similare to rank 1 - 3.
rank 1 - 3 should do something like:

data = comm.bcast(end, root=0)
if data == "endflag":
     sys.exit()


With comm.send() and comm.recv() my processes are running into a deadlock - there is no output, the program loops - same happens with comm.sendrecv().
scatter and gather is not suitable for my project.
bcast and alltoall is maybe an option which will meets my needs, but i dont know how to trigger multiple broadcasts with different content. Like: rank 0 sends an bcast with data1 and he receivs an bcast with data2 and similar rank 1 - 3 are sending data1 and receiving data2.

By the way every rank needs his own "handling", here is some pseudo code which should describe my needs:

if rank == 0:
    while(True):
        recv_data = comm.recv(end, source=MPI.ANY_SOURCE)
        if recv_data == "endflag":
            send_data = comm.bcast(data, root=0)
            sys.exit()
...
if rank == 1:
    while(True):
        recv_data = comm.bcast(end, root=0)
        if recv_data == "endflag":
             sys.exit()
        (generate some strings)
        if data_rank1 == given_string:
           end = "endflag"
           comm.send(end, dest=0)
...
if rank == 2:
    while(True):
        recv_data = comm.bcast(end, root=0)
        if recv_data == "endflag":
             sys.exit()
        (generate some strings)
        if data_rank2 == given_string:
           end = "endflag"
           comm.send(end, dest=0)
...




You must be logged in to post. Please login or register an account.